Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

320
Visualizações
function returns [object object] instead of string Cypress

Want to have single function to get the dynamic text value from application.

getStartDate() function return as [object object] when calling from different function getDate() whereas cy.log(mon...) from getStartDate() gives the correct date in the format of string. Also cy.wrap(mom...) wrap a correct date in string format

   getStartDate(){
         return cy.get('[data-placeholder="Select time range (from)"]').invoke('val').then($da=>{
              cy.log(moment($da,'DD.MM.YYYY HH:mm:ss').format('DD.MM.YYYY HH:mm:ss')+"------------------")  //  returns "03.01.2022 11:10:00"
               return (cy.wrap(moment($da,'DD.MM.YYYY HH:mm:ss').format('DD.MM.YYYY HH:mm:ss').valueOf())) ;Text   // return "03.01.2022 11:10:00"
               
            })
        }

Calling function:

     getDate(){
        cy.log(this.getStartDate().toString()+"------------") // returns [object object]
        }

Kindly let me know how to get the value from getStartDate() by calling through out the application

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

cy.wrap is used to create a cypress chainer object. Moreover, you are returning cy.get(...) from the function, which is an object. You sould try to use Promises:

async getStartDate() {
         const $da = await cy.get('[data-placeholder="Select time range (from)"]').invoke('val');
         cy.log(moment($da,'DD.MM.YYYY HH:mm:ss').format('DD.MM.YYYY HH:mm:ss')+"------------------")  //  returns "03.01.2022 11:10:00"
         return moment($da,'DD.MM.YYYY HH:mm:ss').format('DD.MM.YYYY HH:mm:ss');
}

And use it like this:

getStartDate().then((startDate) => cy.log(startDate));
about 4 years ago · Juan Pablo Isaza Relatório

0

fix code as below :D

cy.log(this.getStartDate().toString(),"------------")

I hope you find an answer!

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda